/**
 * Contains user account change log.
 */
package org.openfk.security.entity;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.sun.istack.NotNull;

/**
 * User account change log.
 * @author Sławomir Czerwiński
 * @version 1
 */
@Entity
@Table(name = "users_logs")
public class UserLog implements Serializable {
	/**
	 * Serial version.
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * User account operation.
	 * @author Sławomir Czerwiński
	 * @version 1
	 */
	public enum Operation {
		/** User account created. */
		CREATE,
		/** User account accepted. */
		ACCEPT,
		/** User account rejected. */
		REJECT,
		/** User account information changed. */
		EDIT,
		/** User account role granted. */
		GRANT,
		/** User account role revoked. */
		REVOKE,
		/** User account suspended. */
		SUSPEND,
		/** User account restored. */
		RESTORE,
		/** User account deleted. */
		DELETE
	}

	/**
	 * User unique and constant identifier.
	 */
	@Id @GeneratedValue @NotNull
	@Column(updatable = false)
	protected Long id;

	/**
	 * Role's application.
	 */
	@NotNull @ManyToOne
	@JoinColumn(
			name="id_principal",
			referencedColumnName="id",
			updatable = false)
	protected User principal;

	/**
	 * The time of the change.
	 */
	@Column(updatable = false)
	protected Timestamp time;

	/**
	 * Role's application.
	 */
	@NotNull @ManyToOne
	@JoinColumn(
			name="id_user",
			referencedColumnName="id",
			updatable = false)
	protected User user;

	/**
	 * User account operation.
	 */
	@Enumerated(EnumType.ORDINAL)
	@Column(updatable = false)
	protected Operation operation;

	/**
	 * User account operation description.
	 */
	@Column(updatable = false)
	protected String description;

}
